#include <stdio.h>
#include <stdlib.h>
#include "C:\Users\max\Desktop\opengl GLSL\helloGPGPU_GLSL-1.0.2\helloGPGPU_GLSL-1.0.2\glew-1.9.0-win32\glew-1.9.0\include\GL/glew.h"
#include "C:\Users\max\Desktop\opengl GLSL\freeglut-2.8.0\freeglut-2.8.0\include\GL/glut.h"


static float angx = 1.0f;
static float angy = 2.0f;
static float angz = 3.0f;
static float rotate_x = 0.0f;
static float rotate_y = 0.0f;
static float rotate_z = 0.0001f;
static float x = 0.0f;
static float y = 0.0f;
static float z = 0.0f;
static float v = 0.0f;

// ----------------------------------------------------------
// specialKeys() Callback Function
// ----------------------------------------------------------
void specialKeys( int key, int x, int y ) {
 
  //  Right arrow - increase rotation by 5 degree
  if (key == GLUT_KEY_RIGHT)
  {
    rotate_y += 5;
  }
	
  //  Left arrow - decrease rotation by 5 degree
  else if (key == GLUT_KEY_LEFT)
  {
	  rotate_y -= 5;
  }
 
  else if (key == GLUT_KEY_UP)
    rotate_x += 5;
 
  else if (key == GLUT_KEY_DOWN)
    rotate_x -= 5;
 
  //  Request display update
  glutPostRedisplay();
 
}

static void keyboard01(unsigned char key, int x, int y)
{
   if((key == 0x1b)||(key == 'q')||(key == 'Q'))
      exit(0); // exit on any of the above keyboard inputs
  if((key == 'f'))
      v=1.0; // exit on any of the above keyboard inputs
  if((key == 'v'))
      v=0.0; // exit on any of the above keyboard inputs
 
}




// Funcao que mostra no display 
void MostranoVideo() {
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
       
  	      glMatrixMode(GL_MODELVIEW);
	      glLoadIdentity();
          glScalef(.2,.2,.2);
		 
          glRotatef(angx, rotate_x , rotate_y ,rotate_z);
		  // glRotatef(angx, rotate_x , rotate_y ,rotate_z);
          glTranslatef(x, y, z);
          glColor3f(0,1,0); // verde 
          
          /*
		  glColor3f(1,0,0);// vermelho 
          glBegin(GL_QUADS);
          glVertex3f(-100,-100,0);
          glVertex3f(100,-100,0);
          glVertex3f(100,100,0);
          glVertex3f(-100,100,0);
          glEnd();  
          
          //glTranslatef(300, 0, 0);
      
          glBegin(GL_QUADS);
          glVertex3f(200,-100,0);
          glVertex3f(200,-100,0);
          glVertex3f(100,100,0);
          glVertex3f(-100,100,0);
          glEnd();  
		   */
		  glutWireDodecahedron();
		  //glutWireCube(100.0);//,20,20);
		  //glRotatef(angx, 0 , 1 ,0);
          
          
          //glutStrokeCharacter(GLUT_STROKE_ROMAN, 'P');
          //glutStrokeCharacter(GLUT_STROKE_ROMAN, ' ');
          //glutStrokeCharacter(GLUT_STROKE_ROMAN, 'o');
          
          Sleep (5);
          glutSwapBuffers();
        
    
} 

void animate()
{
	if (v==1.0)
	{
	    angx += 10.0;
	}
	else 
	{
		angx+=1.0;
	}
	
//        x += 0.5;
        //angz += angz;

        glutPostRedisplay();
}
int main(int argc, char *argv[]) {
  glutInit(&argc, argv); // inicia o Glut
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); // Inicializa o display 
  glutInitWindowSize(500, 500); // incializa a janela 500 X 500 
  glutInitWindowPosition(300, 200); // define a posicao inicial 
  glutCreateWindow("Ola Mundo !"); // cria a janela com o titulo 
 
  glutDisplayFunc(MostranoVideo); // funcao que vai ser mostrada no display 
  glutKeyboardFunc(keyboard01); // funcao de captura de teclaod 
  glutSpecialFunc(specialKeys);
 
  glutIdleFunc(animate); // funcao que controla a animacao 
  
  glutMainLoop(); // loop do glut 
 
  return 0;
} /* end func main */
